﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using System.Diagnostics;

namespace dietyuk_wp
{
    public partial class FoodShowPage : PhoneApplicationPage
    {
        private Food food;

        public Food Food
        {
            get { return food; }
            set { this.food = value; }
        }

        public FoodShowPage()
        {
            InitializeComponent();
        }

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            String foodNdb;
            NavigationContext.QueryString.TryGetValue("foodNdb", out foodNdb);
            var foodSummary = App.foodSummaries.Find(delegate(FoodSummary input)
            {
                return input.o == Int32.Parse(foodNdb);
            });
            food = new Food();
            food.ndbNo = foodSummary.o;
            food.name = foodSummary.n;
            food.nutrients.ENERC_KCAL = foodSummary.e;
            food.nutrients.PROCNT = foodSummary.p;
            Debug.WriteLine("Food: {0}", food);
        }
    }
}